package gdou.gym.util;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class DataUtil {
    public static String getSysTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        return sdf.format(date);
    }

    public static String getOrderTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        Date date = new Date();
        return sdf.format(date);
    }

    public static String getThisDayBeforeByNums(String curDate, Integer nums) {
        Calendar c = Calendar.getInstance();
        Date date = null;
        try {
            date = new SimpleDateFormat("yyyy-MM-dd").parse(curDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        c.setTime(date);
        int day = c.get(Calendar.DATE);
        c.set(Calendar.DATE, day - nums);
        return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
    }


    public static List<String> getThisDayAfterByNumsList(String curDate, Integer nums) {
        Calendar c = Calendar.getInstance();
        Date date = null;
        try {
            date = new SimpleDateFormat("yyyy-MM-dd").parse(curDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        c.setTime(date);
        int day = c.get(Calendar.DATE);
        List<String> dates = new LinkedList<>();
        for (int i = nums; i > 0; i--) {
            c.set(Calendar.DATE, day - i);
            dates.add(new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()));
        }
        return dates;

    }


}
